<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../css/mystyle.css" />
<title>QUẢN LÝ BÀI VIẾT</title>
</head>     
<body class="pagebody">
 <?php
                    include 'product_model.php';
                    if(isset($_POST['submit'])&& $_POST['submit']=='Add New Product')
                    {
                        if($_POST['txtProductName']!=NULL && $_POST['txtDescription']!=NULL && $_POST['txtPrice']!=NULL )
                        {
                            $name=$_POST['txtProductName'];
                            $description=$_POST['txtDescription'];
                            $price=$_POST['txtPrice'];
                            $size=$_POST['txtSize'];
                            $categoryid=$_POST['selectCate'];
                            $nameimg=$_FILES['img']['name'];
                           
                            $url="../upload/".$_FILES['img']['name'];
                            $result=  InsertProduct($name, $description, $url, $price, $size, $categoryid);
                           if($result>0)
                            {
                                move_uploaded_file($_FILES['img']['tmp_name'],"../upload/".$_FILES['img']['name']);
                                 echo '<div class="message">Add new product Successful</div>';
                                  header("refresh:1;url=v_addNewProduct.php");
                            }
                            else
                                echo'Loi'.  mysql_error();
                      }
                      else
                          {
                                 echo '<div class="message">Nhập đủ thông tin</div>';
                                  header("refresh:1;url=v_addNewProduct.php");
                            }

                    }
                    //
                    if(isset($_POST['submit'])&& $_POST['submit']=='Update Product')
                    {
                        if($_POST['txtProductName']!=NULL && $_POST['txtDescription']!=NULL && $_POST['txtPrice']!=NULL )
                        {
                            $productID=$_POST['txtProductID'];
                            $name=$_POST['txtProductName'];
                            $description=$_POST['txtDescription'];
                            $price=$_POST['txtPrice'];
                            $size=$_POST['txtSize'];
                            $categoryid=$_POST['selectCate'];
                            $url="../upload/".$_FILES['img']['name'];
                          // $result=  UpdateProduct($name, $description, $price, $size, $categoryid,$url, $productID);
                            $result=  UpdateProductDemo($name, $description,$price,$size,$categoryid,$url, $productID);
                           if($result!=0)
                            {
                                 echo '<div class="message">Update product Successful</div>';                            
                                  move_uploaded_file($_FILES['img']['tmp_name'],"../upload/".$_FILES['img']['name']);
                                   header("refresh:1;url=v_product_manage.php");
                                 
                            }
                            else
                            {
                                echo'<br>Not Update successful';
                                header("refresh:1;url=v_addNewProduct.php");
                       
                            }
                      }
                      else
                          {
                                 echo '<div class="message">Nhập đủ thông tin</div>';
                                 header("refresh:1;url=v_product_manage.php");
                            }
                    
                    }
                    if(isset($_GET['IDProduct']))
                    {
                     $productID=$_GET['IDProduct'];
                    $rs=  DeleteProduct($productID);
                    if($rs>0)
                    {
                        echo '<div class="message">Delete Success</div>';
                        header("refresh:1;url=v_product_manage.php");       
                    }
                    }
                    
                ?>
</body>
</html>